package com.xj.center.manager.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ie.api.center.manager.feign.TenantClient;
import com.xj.center.manager.mapper.TenantMapper;
import com.xj.center.manager.service.TenantService;
import com.xj.common.bean.R;
import com.xj.common.bean.constant.Common;
import com.xj.common.bean.point.PointValue;
import com.xj.common.dto.TenantDto;
import com.xj.common.model.Tenant;
import com.xj.common.utils.KafkaProducer;
import com.xj.common.utils.RedisUtil;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 实时数据接口
 * @author wsp
 *
 */
@RestController
@RequestMapping(value = Common.Service.IE_MANAGER_TENANT)
public class TenantAPI implements TenantClient {

	@Resource
	private TenantService tenantService;

	@RequestMapping(value = Common.Service.IE_MANAGER_TENANT_FIND,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@CrossOrigin
	public R<Tenant> selectByName(
			@RequestBody String tenantName
			)
	{
		//String name = "test";
		try {
			Tenant select = tenantService.selectByName(tenantName);
			if (null != select) {
				return R.ok(select);
			}
		} catch (Exception e) {
			return R.fail(e.getMessage());
		}
		return R.fail("Resource does not exist");

		
	}

	@Override
	@RequestMapping(value = Common.Service.IE_MANAGER_TENANT_LIST,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@CrossOrigin
	public R<List<Tenant>> list() {
		try {
			Page<Tenant> select = tenantService.list(new TenantDto());
			if (null != select) {
				return R.ok(select.getRecords());
			}
		} catch (Exception e) {
			return R.fail(e.getMessage());
		}
		return R.fail("Resource does not exist");
	}


}
